use serde::Deserialize;
use std::fs;

#[derive(Debug, Deserialize)]
pub struct Config {
    pub database: DatabaseConfig,
    pub port: u16,
    pub max_connections: usize,
    pub workers: usize

}

#[derive(Debug, Deserialize)]
pub struct DatabaseConfig {
    pub url: String,
    pub max_connections: u32

}

impl Config {
    // 加载 YAML 配置文件的方法
    pub fn from_yaml(file_path: &str) -> Result<Self, Box<dyn std::error::Error>> {
        let config_str = fs::read_to_string(file_path)?;
        let config: Config = serde_yaml::from_str(&config_str)?;
        Ok(config)
    }
}
